package com.cjq.util;


import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

import java.util.HashMap;

public class SMSUtil {
    public static void main(String[] args) {
        send("13542066480","666666");
    }


    public static boolean send(String phoneNumber,String code) {
        System.out.println("已经将短息发送到手机号:"+phoneNumber+",验证码为："+code);
        return true;
    }

}


/*
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tSdy44hsJ9PWRCoU8wq", "pPOIqG6BNcvfFZzAlnyuoNVZ1tThiQ");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        request.putQueryParameter("SignName", "学七快递");    //短信签名名称
        request.putQueryParameter("TemplateCode", "SMS_220636795");      //短信模板CODE
        request.putQueryParameter("TemplateParam", "JSON格式参数列表");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            String json = response.getData();
            Gson g = new Gson();
            HashMap result = g.fromJson(json, HashMap.class);
            if ("OK".equals(result.get("Message"))) {
                return true;
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }


public static boolean send(String phoneNumber){
        DefaultProfile profile=DefaultProfile.getProfile("cn-hangzhou","你的 accessKeyId","你的AccessKeySecret");
        IAcsClient client=new DefaultAcsClient(profile);
        CommonRequest request=new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId","cn-hangzhou");
        request.putQueryParameter("PhoneNumbers",phoneNumber);
        request.putQueryParameter("SignName","短信签名名称");
        request.putQueryParameter("TemplateCode","短信模板CODE");
        request.putQueryParameter("TemplateParam","JSON格式参数列表");
        try{
        CommonResponse response=client.getCommonResponse(request);
        System.out.println(response.getData());
        String json=response.getData();
        Gson g=new Gson();
        HashMap result=g.fromJson(json,HashMap.class);
        if("OK".equals(result.get("Message"))){
        return true;
        }
        }catch(ServerException e){
        e.printStackTrace();
        }catch(ClientException e){
        e.printStackTrace();
        }
        return false;
        }*/
